package com.ruoyi.wms.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.wms.domain.WmsCustom;
import com.ruoyi.wms.service.IWmsCustomService;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 自定义模板Controller
 *
 * @author ruoyi
 * @date 2022-04-15
 */
@RestController
@RequestMapping("/custom")
public class WmsCustomController extends BaseController {
  @Autowired private IWmsCustomService wmsCustomService;

  /** 查询自定义模板列表 */
  @RequiresPermissions("wms:custom:list")
  @GetMapping("/list")
  public TableDataInfo list(WmsCustom wmsCustom) {
    startPage();
    List<WmsCustom> list = wmsCustomService.selectWmsCustomList(wmsCustom);
    return getDataTable(list);
  }

  /** 导出自定义模板列表 */
  @RequiresPermissions("wms:custom:export")
  @Log(title = "自定义模板", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(HttpServletResponse response, WmsCustom wmsCustom) {
    List<WmsCustom> list = wmsCustomService.selectWmsCustomList(wmsCustom);
    ExcelUtil<WmsCustom> util = new ExcelUtil<WmsCustom>(WmsCustom.class);
    util.exportExcel(response, list, "自定义模板数据");
  }

  /** 获取自定义模板详细信息 */
  @RequiresPermissions("wms:custom:query")
  @GetMapping(value = "/{id}")
  public AjaxResult getInfo(@PathVariable("id") Long id) {
    return AjaxResult.success(wmsCustomService.selectWmsCustomById(id));
  }

  /** 新增自定义模板 */
  @RequiresPermissions("wms:custom:add")
  @Log(title = "自定义模板", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(@RequestBody WmsCustom wmsCustom) {
    return toAjax(wmsCustomService.insertWmsCustom(wmsCustom));
  }

  /** 修改自定义模板 */
  @RequiresPermissions("wms:custom:edit")
  @Log(title = "自定义模板", businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult edit(@RequestBody WmsCustom wmsCustom) {
    return toAjax(wmsCustomService.updateWmsCustom(wmsCustom));
  }

  /** 删除自定义模板 */
  @RequiresPermissions("wms:custom:remove")
  @Log(title = "自定义模板", businessType = BusinessType.DELETE)
  @DeleteMapping("/{ids}")
  public AjaxResult remove(@PathVariable Long[] ids) {
    return toAjax(wmsCustomService.deleteWmsCustomByIds(ids));
  }
}
